﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Data.ConnectionUI;
using devtm.Configuration;
using System.Configuration;
using System.Windows.Forms;
using devtm.Types.LazyLoading;
using devtm.Configuration.Models;

namespace devtm.Editor.Configuration.Templates
{


    public static class ConfigurationProviderSettingsActions
    {


        #region RSA

        public static bool InitializeProviderSettingsRSA(IElementSection sectionElement)
        {

            return true;
        }

        public static bool IsRsaProtectedConfigurationProvider(IElementSection sectionElement)
        {
            string path = sectionElement.Path;
            return CanInitializeProviderSettings(sectionElement, path, "RsaProtectedConfigurationProvider");
        }

        public static ReturnIsValid RsaDescriptionIsValid(object source) { return ReturnIsValid.Ok; }
        public static ReturnIsValid RsaKeyContainerNameIsValid(object source) { return ReturnIsValid.Ok; }
        public static ReturnIsValid RsaCspProviderNameIsValid(object source) { return ReturnIsValid.Ok; }
        public static ReturnIsValid RsaUseMachineContainerIsValid(object source) { return ReturnIsValid.Ok; }
        public static ReturnIsValid RsaUseOAEPIsValid(object source) { return ReturnIsValid.Ok; }

        #endregion



        #region Dataprotection

        public static bool InitializeProviderSettingsDataprotection(IElementSection sectionElement)
        {


            return true;
        }

        public static bool IsDataProtectionConfigurationProvider(IElementSection sectionElement)
        {
            string path = sectionElement.Path;
            return CanInitializeProviderSettings(sectionElement, path, "DataProtectionConfigurationProvider");
        }

        public static ReturnIsValid DataProtectionDescriptionIsValid(object source) { return ReturnIsValid.Ok; }
        public static ReturnIsValid DataProtectionUseMachineProtectionIsValid(object source) { return ReturnIsValid.Ok; }
        public static ReturnIsValid DataProtectionKeyEntropyIsValid(object source) { return ReturnIsValid.Ok; }

        #endregion



        #region Common

        public static bool CanInitializeProviderSettings(IElementSection sectionElement)
        {

            string path = sectionElement.Path;

            return CanInitializeProviderSettings(sectionElement, path, string.Empty);

        }

        public static bool CanInitializeProviderSettings(IElementSection sectionElement, string path, string type)
        {

            var toto = sectionElement.ConfigurationElement as System.Configuration.ProviderSettings;

            return toto != null
                && path.StartsWith(@"\configProtectedData\providers\")
                && (string.IsNullOrEmpty(@type) || path.EndsWith(@type));

        }

        #endregion

    }
}

